Preflight Request
CORSで、Simple Requestでない場合に事前に送るRequestのこと
OPTIONSmethodで送る
以下のようなheaderを付ける
Origin Header
Access-Control-Reuqest-Methods
Access-Control-Request-Headers
例
http://S.com/hogeにreqを送っている
code:req
OPTIONS /hoge HTTP/1.1
Host: S.com
Origin: http://X.com
Access-Control-Request-Metho: POST
Access-Control-Request-Headers: My-Custom-Header
自分(client)がX.com
送っている相手が、S.com
CORSで許可されていないPOSTやMy-Custom-Headerの使用を許可してもらうためのrequestを送っている
これへの返却例
これはS.comのresponse
code:res
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://X.com
Access-Control-Allow-Methods: GET, POST, PUT
Access-Control-Allow-Headers: My-Custom-Header
headerの対応
table:対応
Preflight Requestのheader response header
Origin Header Access-Control-Allow-Origin
Access-Control-Reuqest-Method Access-Control-Allow-Method
Access-Control-Request-Headers Access-Control-Allow-Headers
無理だった場合、405 Method Not Allowedが返ってくる
Preflight Requestはなぜ必要なのか?
参考
『Webブラウザセキュリティ』 p.39 ~